<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<%java.util.Random r=new java.util.Random();  %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript"><!--

	function checkForm2(){
		var objs = document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("请选择待操作的项！");
			return false;
		}else if(sign > 1){
			alert("只能选择一个待操作项！");
			return false;
		}
		return true;
	}

	function updateCustomer(){
		if(checkForm2()){
			var objs = document.getElementsByName("id");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			var isWrite = document.getElementById("share_"+id);
			if(isWrite.value != "" && isWrite.value == '1'){
				window.location.href = "./customerManage.do?action=preUpdateCustomer&id="+id+"&sign=2";
				window.location.target = "main";
			}else{
				alert("您对此共享客户只有可读权限，不能修改客户信息！");
			}
		}
	}
	
	function addLinkman(id){
		window.location.href = "./linkman.do?action=preAddLinkman&customerId="+id+"&sign=2";
		window.location.target = "main";
	}
	
	function updateLinkman(id){
		window.location.href = "./linkman.do?action=preUpdateLinkman&customerId="+id+"&sign=2";
		window.location.target = "main";
	}
	
	function shareCustomer(){
		if(checkForm2()){
			var objs = document.getElementsByName("id");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			var isWrite = document.getElementById("share_"+id);
			var userId = document.getElementById("userId_"+id);
			if(isWrite.value != "" && isWrite.value == '1' && userId.value == "<c:out value='${userId}'/>"){
				window.location.href = "./customerManage.do?action=shareCustomer&customerId="+id+"&sign=2";
				window.location.target = "main";
			}else{
				alert("此客户是别人共享给您的，不能在共享给其他人！");
			}
		}
	}

	function addSaleRecordCare(){
		if(checkForm2()){
			var objs = document.getElementsByName("id");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			var isWrite = document.getElementById("share_"+id);
			if(isWrite.value != "" && isWrite.value == '1'){
				window.location.href = "./saleRecord.do?action=preAddSaleRecordCare&customerId="+id;
				window.location.target = "main";
			}else{
				alert("您对此共享客户只有可读权限，不能新增日常关怀！");
			}
		}
	}
	
	function deptContractCustomer(){
		window.location.href = "./contractCustomer.do?action=deptCustomer";
		window.location.target = "main";
	}
	
	//function advancedQueryDialog(){
	//	var url = "advancedAuery.html";
	//	var dlgParam = "dialogHeight:360px;dialogWidth:450px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
	//	window.showModalDialog(url,"",dlgParam);
	//}
	
	
	function pageCustomer(flag){
		document.contractCustomerForm.action = "./contractCustomer.do?action=display&flag="+flag;
		document.contractCustomerForm.target = "main";
		document.contractCustomerForm.submit();
	}
	
	function initPage(){
		if("<c:out value='${deleteResult}'/>" == 1){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}else if("<c:out value='${deleteResult}'/>" == 2){
			alert("保存成功！");
		}
	}
	function advancedQueryDialog(){
		var url = "./contractCustomer.do?action=advancedQueryDialog1&radom="+<%=r.nextInt(100)%>;
		var dlgParam = "dialogHeight:360px;dialogWidth:450px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		var rt = window.showModalDialog(url,"",dlgParam);
		if(rt != undefined){		
			//根据从子窗口得到的值，从中提取customerCode,customerName,industryId,areaId,
			//customerSourceId,requireDesc,startCreateDate,endCreateDate,startLastLinkDate,endLastLinkDate
			var tStr = rt.split(",");
											
			document.getElementById("customerName").value = tStr[0];
			document.getElementById("salePerson").value = tStr[1];
			document.getElementById("industryId").value = tStr[2];
			document.getElementById("areaId").value = tStr[3];
			document.getElementById("requireDesc").value = tStr[4];
			document.getElementById("sContactDate").value = tStr[5];
			document.getElementById("eContactDate").value = tStr[6];
			document.getElementById("startbackDate").value = tStr[7];
			document.getElementById("endbackDate").value = tStr[8];
			document.getElementById("backCostDesc").value = tStr[9];
			
			
			document.contractCustomerForm.action = "./contractCustomer.do";
			document.contractCustomerForm.target = "main";
			document.contractCustomerForm.submit();
		}
	}

--></script>
</head>
<body onload="initPage()">
<form name="contractCustomerForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab">老客户档案</td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;padding-top: 4px;">
							<c:if test="${isUpdateContractCustomer == 1}">
							<a class="update" href="javascript:updateCustomer();" hidefocus="true" title="修改客户">修改</a>
							</c:if>
							<a class="asearch" href="javascript:advancedQueryDialog();" hidefocus="true">高级查询</a>
							<c:if test="${isShareContractCustomer == 1}">
							<a class="share" href="javascript:shareCustomer();" hidefocus="true">共享</a>
							</c:if>
							<a class="care" href="javascript:addSaleRecordCare();" hidefocus="true">日常关怀</a>
						</td>
						<!-- 
						<td></td>
						<td valign="bottom" align="right">
							<c:if test="${isViewDeptContractCustomer == 1}">
							<a href="javascript:deptContractCustomer();">查看部门老客户档案</a>&nbsp;&nbsp;
							</c:if>
						</td>
						 -->
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td class="title_lab">老客户档案</td>
						<td align="right" valign="">
							<!-- page -->
							<table class="table_page2">
								<tr>
									<td valign="bottom">
										<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
										<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
										<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
										共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>&nbsp;&nbsp;&nbsp;
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr><td colspan="3" height="2"></td></tr>
					<tr>
						<td colspan="2">
							<table class="table">
								<tr>
									<td valign="top">
										<table class="table_style" style="width: 1300px;  word-break:break-all">
											<tr>
												<td class="title" width="8"></td>
												<td class="title" width="30">选择</td>
												<td class="title" width="30">共享</td>
												<td class="title" width="30">状态</td>
												<td class="title" width="300">客户名称</td>
												<td class="title" width="60">销售代表</td>
												<td class="title" width="60">建档日期</td>
												<td class="title_sort" width="60" onclick="recordSort('lastLink','16')">
													最后联系<img id="16" src="./images/arrow_off.gif" style="vertical-align: middle;">
												</td>
												<td class="title" width="130">注册地址</td>
												<td class="title" width="300">销售进度</td>	
												<td class="title" width="60">行业</td>
												<td class="title" width="60">区域</td>
											</tr>
											<c:forEach var="customer" items="${customers}">
											<tr onmouseover="onmousemoveChange(this,'img${customer.id}')" onmouseout="onmouseoutChange(this,'img${customer.id}')">
												<td height="16" width="8" align="right"><img id="img${customer.id}" src="./images/table_sign2.bmp"></td>
												<td>
													<input id="id" name="id" type="checkbox" value="${customer.id}" />
													<!-- 
													<c:if test="${isAddContractLinkman == 1}">
													<a href="javascript:javascript:addLinkman('${customer.id}');" title="新增联系人">新增</a>
													</c:if>
													<c:if test="${isUpdateContractCustomer == 1}">
													<a href="javascript:javascript:updateLinkman('${customer.id}');" title="修改联系人">修改</a>
													</c:if>
													 -->
													<input id="share_${customer.id}" name="share_${customer.id}" type="hidden" value="${customer.isWrite}"/>
													<input id="customer_${customer.id}" name="customer_${customer.id}" type="hidden" value="${customer.customerName}"/>
													<input id="userId_${customer.id}" name="userId_${customer.id}" type="hidden" value="${customer.salePersonId}"/>
												</td>
												<td align="center">
													<c:if test="${customer.isShare == 1}">
													<img class="btn_img" src="./images/share.gif" onclick="" title="<fmt:message key='customer.lable.share'/>">
													</c:if>
												</td>
												<td align="center">
													<c:if test="${customer.isFollow == 1}">
													<img class="btn_img" src="./images/follow.gif" onclick="" title="<fmt:message key='customer.lable.follow'/>">&nbsp;&nbsp;
													</c:if>
												</td>												
												<td align="left"><a href="./customerManage.do?action=customerDetail&customerId=${customer.id}&sign=22" target="main">${customer.customerName}</a></td>
												<td>${customer.salePerson}</td>
												<td><fmt:formatDate value="${customer.createDate}" pattern="yyyy-MM-dd"/></td>
												<td><fmt:formatDate value="${customer.lastLink}" pattern="yyyy-MM-dd"/></td>
												<td>${customer.summaryAddress}</td>
												<td>${customer.customItem2}</td>
												<td>
													<c:forEach var="range" items="${ranges['110']}">
														<c:if test='${customer.industryId == range.id}'>${range.rangeValue}</c:if>
													</c:forEach>
												</td>
												<td>
													<c:forEach var="range" items="${ranges['111']}">
														<c:if test='${customer.areaId == range.id}'>${range.rangeValue}</c:if>
													</c:forEach>
												</td>
											</tr>
											</c:forEach>
										</table>
									</td>
								</tr>
								<tr>
									<td align="left" valign="bottom">
										<!-- page -->
										<table id="tp" class="table_page">
											<tr>
												<td>&nbsp;&nbsp;
													<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
													<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
													<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
													共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="customerName" name="customerName" type="hidden" value="${queryCustomer.customerName }"/>
	<input id="salePerson" name="salePerson" type="hidden" value="${queryCustomer.salePerson }"/>
	<input id="industryId" name="industryId" type="hidden" value="${queryCustomer.industryId }"/>
	<input id="areaId" name="areaId" type="hidden" value="${queryCustomer.areaId }"/>
	<input id="requireDesc" name="requireDesc" type="hidden" value="${queryCustomer.areaId }"/>
	<input id="sContactDate" name="sContactDate" type="hidden" value="${queryCustomer.sContactDate }"/>
	<input id="eContactDate" name="eContactDate" type="hidden" value="${queryCustomer.eContactDate }"/>
	<input id="startbackDate" name="startbackDate" type="hidden" value="${queryCustomer.startbackDate }"/>
	<input id="endbackDate" name="endbackDate" type="hidden" value="${queryCustomer.endbackDate }"/>
	
	<input id="backCostDesc" name="backCostDesc" type="hidden" value="${queryCustomer.backCostDesc }"/>
</form>
</body>
</html>